import React from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import {Input,Button,message,Modal} from 'antd'
import InputItem from '../../../components/InputItem'
import InnovationStudioController from '@/services/InnovationStudio/InnovationStudioController';
const {confirm} = Modal
// confirm 这是确认框，是Modal的子组件
class NewStudio extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            datas:{}
         };
    }
    getResult=(result)=>{
        this.setState({result})
    }
    onRef=(ref)=>{
        this.setState({
            modal:ref
        })
    }
    submit=()=>{
        let {datas} = this.state
        let that = this
        let userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        datas.name = userInfo.name
        datas.userName = userInfo.userName
        let roleName = userInfo.roleName
        if(roleName.indexOf("省级")!==-1){
            datas.level='省级'
        }
        if(roleName.indexOf("市级")!==-1){
            datas.level='市级'
        }
        if(roleName.indexOf("市级")===-1&&roleName.indexOf("省级")===-1){
            datas.level=''
        }
        console.log('数据验证',datas)
        if(!datas.studioName){
            message.error('工作室名称未填写')
            return
            // 数据验证，当验证条件被激活时，采用return终止方法的执行，
        }
        if(!datas.description){
            message.error('工作室简介未填写')
            return
        }
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                InnovationStudioController.createdStudio(datas).then(r=>{
                    if(r&&r.status===200){
                        message.success('提交成功')
                        that.props.onCancel()
                    }
                })
                console.log(datas)
            }
        })
    }
    handleChange=(datas)=>{
        this.setState({datas})
    }
    render() {
        const {datas}=this.state
        const columns=[
            {name:'工作室名称',keyName:'studioName',valueType:'text',value:datas.studioName},
            {name:'工作室简介',keyName:'description',valueType:'textArea',value:datas.description},  
        ]
        return (
            <div>
                <InputItem columns={columns} onChange={this.handleChange}/>
                <Button onClick={this.submit} type={'primary'}>提交</Button>
            </div>
        );
    }
}

export default NewStudio;